package com.cyz.user.controller;

import com.cyz.common.dto.CardDto;
import com.cyz.user.userService.CardService;
import com.cyz.user.userService.ShopService;
import com.cyz.common.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//TODO: 权限管理没做

@Api(tags = "用户端课程相关接口")
@RestController
@RequestMapping("/card")
public class CardController {

    @Autowired
    private CardService cardService;
    @Autowired
    private ShopService shopService;

    @ApiOperation(value = "查询免费课程")
    @GetMapping("/queryCards")
    public R queryCards() {
        return cardService.queryCards();
    }

    @ApiOperation(value = "查询免费课程以及按钮")
    @GetMapping("/queryCardsAndButtons")
    public R queryCardsAndButtons() {
        return cardService.queryCardsAndButtons();
    }

    @ApiOperation(value = "查询付费课程")
    @GetMapping("/queryShops")
    public R queryShops() {
        return shopService.queryShops();
    }

    @ApiOperation(value = "根据id查课程")
    @GetMapping("/getCardById")
    public R getCardById(Integer id){
        return cardService.getCardById(id);
    }

    @ApiOperation(value = "更新浏览量")
    @PutMapping("/updateViewCount/{id}")
    public R updateViewCount(@PathVariable("id") Integer id){
        return cardService.updateViewCount(id);
    }

    @ApiOperation(value = "查询热门课程")
    @GetMapping("/queryHotCards")
    public R queryHotCards(){
        return cardService.queryHotCards();
    }

    @ApiOperation(value = "查询收藏的免费课程")
    @GetMapping("/queryMyCards")
    public R queryMyCards(){
        return cardService.queryMyCards();
    }

    @ApiOperation(value = "收藏免费课程")
    @PostMapping("/addMyCard")
    public R addMyShop(@RequestBody CardDto cardDto){
        return cardService.addMyCard(cardDto);
    }
}
